//
//  NoItemView.m
//  CarTown
//
//  Created by xionghao on 15/9/6.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "NoItemView.h"


@interface NoItemView ()
@property (nonatomic,strong) UIImageView *noitemimageview;
@property (nonatomic,strong) UILabel *titlelable;
@end
@implementation NoItemView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        UIImageView *noitemimageview=[[UIImageView alloc]init];
        [self addSubview:noitemimageview];
        _noitemimageview=noitemimageview;
        _noitemimageview.contentMode=UIViewContentModeScaleAspectFit;
        self.backgroundColor=bgGarycolor;
        _titlelable=[[UILabel alloc]init];
        [self addSubview:_titlelable];
        [_titlelable setFont:[UIFont systemFontOfSize:14]];
        _titlelable.textColor=textnormalGary;
        _titlelable.textAlignment=NSTextAlignmentCenter;
    }
    return self;
}

+(instancetype)viewWithType:(NoItemViewTYPE)type{
    NoItemView *item=[[NoItemView alloc]initWithFrame:CGRectMake(0, 0, XHScreenwidth, XHScreenheight)];
    switch (type) {
        case FAVTYPE:
            item.titlelable.text=@"暂无收藏的车源";
            item.noitemimageview.image=[UIImage imageNamed:@"noitemfav"];
            break;
        case STARTTYPE:
             item.titlelable.text=@"暂无关注的商家";
            item.noitemimageview.image=[UIImage imageNamed:@"icon_start"];
            break;
        case MYCARTYPE:
             item.titlelable.text=@"暂无车源";
            item.noitemimageview.image=[UIImage imageNamed:@"mynocar"];
            item.height=XHScreenheight-64-40-46;
            break;
        case MYFINDCARTYPE:
            item.titlelable.text=@"暂无求购";
            item.noitemimageview.image=[UIImage imageNamed:@"mynocar"];
            break;
        case MYHISTORYTYPE:
            item.titlelable.text=@"暂无历史记录";
            item.noitemimageview.image=[UIImage imageNamed:@"nohistory"];
            break;
        case MYMESSAGETYPE:
            item.titlelable.text=@"暂无消息通知";
            item.noitemimageview.image=[UIImage imageNamed:@"nomessage"];
            break;
        default:
            break;
    }
    return item;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat width=120;
    CGFloat height=width;
    CGFloat x=(XHScreenwidth-width)/2;
    CGFloat y=(XHScreenheight-height-64-64)/2;
    _noitemimageview.frame=CGRectMake(x, y, width, height);
    
    _titlelable.frame=CGRectMake(0, y+height+8, XHScreenwidth, 18);
    
}

-(void)hide{
   
    [UIView animateWithDuration:0.5 animations:^{
        self.alpha=0.0;
    }];
}

-(void)show{
       [UIView animateWithDuration:0.5 animations:^{
        self.alpha=1.0;
    }];

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
